using net_work.Config;
using net_work.Data.DTO.Cou;
using net_work.Data.Entity.Cou;
using net_work.IRepository.Cou;

namespace net_work.Repository.Cou;

public class TeacherTeachingRepository(ApplicationDbContext dbContext)
    : Repository<TeacherTeaching>(dbContext), ITeacherTeachingRepository
{
    public async Task<long> InsertAsync(TeacherTeachingAddRequest teacherTeachingAddRequest)
    {
        var newTeacherTeaching = new TeacherTeaching
        {
            Remark = teacherTeachingAddRequest.Remark,
            TeacherId = teacherTeachingAddRequest.TeacherId,
            TeachId = teacherTeachingAddRequest.TeachId
        };
        await dbContext.TeacherTeachings.AddAsync(newTeacherTeaching);
        await dbContext.SaveChangesAsync();
        return newTeacherTeaching.Id;
    }

    public async Task<bool> UpdateAsync(TeacherTeachingUpdateRequest teacherTeachingUpdateRequest)
    {
        var teacherTeaching = await dbContext.TeacherTeachings.FindAsync(teacherTeachingUpdateRequest.Id);

        if (teacherTeaching == null)
        {
            return false;
        }

        teacherTeaching.Remark = teacherTeachingUpdateRequest.Remark;
        teacherTeaching.TeachId = teacherTeachingUpdateRequest.TeachId;
        teacherTeaching.TeacherId = teacherTeachingUpdateRequest.TeacherId;

        await dbContext.SaveChangesAsync();
        return true;
    }
}